--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_par_strucjur AS (SELECT * FROM &erp.par_strucjur WHERE 1=2);




DELETE FROM se_par_strucjur;

 INSERT INTO se_par_strucjur
 (SELECT id strucjur_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle strucjur_lib,
         NULL strucjur_lib2
    FROM uv_cstrucjur) ;

 UPDATE se_par_strucjur tf SET enreg_id=(select enreg_id FROM &erp.par_strucjur f WHERE f.strucjur_cod=tf.strucjur_cod) ;
 UPDATE se_par_strucjur tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('strucjur_cod','par_strucjur','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source,strucjur_cod, enreg_id, enreg_s, strucjur_lib, strucjur_lib2
FROM (
  SELECT 'uv' source ,g.* FROM se_par_strucjur g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_strucjur g
  )
GROUP BY  strucjur_cod, enreg_id, enreg_s, strucjur_lib, strucjur_lib2
HAVING Count(1)!=2) r
ORDER BY strucjur_cod;